import org.newdawn.slick.Color;


public class GuiButton {

	
	
	public GuiButton(int x, int y, int width, int height, String text, String action) {
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		this.text = text;
		this.action = action;
		
		this.paddingx = 40;
		this.paddingy = 10;
		
		this.enabled = false;
		
		this.state = ButtonState.inactive;
		this.prevstate = ButtonState.inactive;
		this.color = colorinactive;
		
		if (width > maxbuttonwidth) {
			maxbuttonwidth = width;
			maxbuttonx = x;
		}
	}
	
	public String onClick() {
		color = coloractive;
		state = ButtonState.active;
		prevstate = ButtonState.inactive;
		return action;
	}
	
	public void onHover() {
		color = colorhover;
		if (!state.equals(ButtonState.hover)) {
			prevstate = state;
			state = ButtonState.hover;
		}
	}
	
	public void onLeave() {
		color = (prevstate.equals(ButtonState.inactive) ? colorinactive : coloractive);
		state = prevstate;
		
	}
	
	public void onDeactivate() {
		color = colorinactive;
		prevstate = ButtonState.inactive;
		state = ButtonState.inactive;
		System.out.println("Deact " + action);
	}
	
	public boolean isPointWithin(int mx, int my) {
		return (mx > x && mx < x + width &&
				my > y && my < y + height);
	}
	
	public Color getColor() {
		return color;
	}
	public int x,
			   y,
			   width,
			   height,
			   paddingx,
			   paddingy;
	
	public String action,
				  text;
	
	public boolean enabled;
	
	public ButtonState prevstate;
	public ButtonState state;
	
	public enum ButtonState {inactive, hover, active};
	
	public Color color;
	public static Color colorhover = Color.magenta;
	public static Color colorinactive = Color.white;
	public static Color coloractive = Color.cyan;
	
	public static int maxbuttonwidth = 0;
	public static int maxbuttonx = 0;
}
